package com.uex.dev.manage.common.base;

import lombok.Data;

import java.io.Serializable;

/**
 * @author wangc
 * @create 2023/10/27
 * @description 统一返回对象
 */
@Data
public class ModelResult<T> implements Serializable {
    /**
     * 状态码
     */
    private final int code;
    /**
     * 提示信息
     */
    private final String msg;
    /**
     * 返回数据
     */
    private T data;

    public ModelResult(ResultCodeConstants resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getResultDesc();
    }

    public ModelResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ModelResult(T data) {
        this(ResultCodeConstants.SUCCESS);
        this.data = data;
    }

    public static final ModelResult<Void> SUCCESS_VOID_RESULT = new ModelResult<>(ResultCodeConstants.SUCCESS);
    public static final ModelResult SUCCESS_RESULT = new ModelResult<>(ResultCodeConstants.SUCCESS);
    public static final ModelResult SYSTEM_ERROR_RESULT = new ModelResult<>(ResultCodeConstants.SYSTEM_ERROR);
    public static final ModelResult TOKEN_TIMEOUT_ERROR = new ModelResult<>(ResultCodeConstants.TOKEN_TIMEOUT_ERROR);
    public static final ModelResult SESSION_ERROR = new ModelResult<>(ResultCodeConstants.SESSION_ERROR);
    public static final ModelResult AUTHENTICATION_REQUIRED_ERROR = new ModelResult<>(ResultCodeConstants.AUTHENTICATION_REQUIRED_ERROR);

}
